package gui;

import javax.swing.table.AbstractTableModel;

import tools.Tools;
import candidates.ArticleCandidate;

public class TableModelKandidaten extends AbstractTableModel {

	private static final long serialVersionUID = 0;
	private ArticleCandidate[] data;

	public TableModelKandidaten(){
		
	}
	public TableModelKandidaten(ArticleCandidate[] data){
		setData(data);
	}
	
	@Override
	public int getColumnCount() {
		return 4;
	}

	@Override
	public int getRowCount() {
		return data.length;
	}
	
	@Override
	public String getColumnName(int column){
		switch (column){
		case 0: return "Ressource";
		case 1: return "Gewicht"; 
		case 2: return "Anzahl Annotationen";
		case 3: return "Text";
		}
		return null;
	}
	
	public void setData(ArticleCandidate[] data) {
		this.data = data;
	}
	
	public String getFullText(int row){
		return data[row].getText();
	}

	@Override
	public Object getValueAt(int row, int column) {
		switch (column){
		case 0: return data[row].toString();//resource
		case 1: return data[row].getGewicht();//gewicht
		case 2: return data[row].getAnzahlAnnotationen();//anzahl annotationen
		case 3: return Tools.entferneZeilenAmAnfang(data[row].getText(), 4);//text
		}
		return null;
	}
	
	@Override
	public Class<?> getColumnClass(int column) {
		switch (column) {
		case 0:
			return String.class;
		case 1:
			return Double.class;
		case 2:
			return Integer.class;
		case 3:
			return String.class;
		default:
			return Object.class;
		}
	}
}
